﻿#ifndef _STREAM_ARCHIVE_H_
#define _STREAM_ARCHIVE_H_

#pragma once

#include "kernel/dll_cfg.h"
#include "kernel/threading/mutex.h"
#include "kernel/OgreArchiveFactory.h"

namespace FD 
{
	namespace Kernel
	{
		class FD_Kernel_Export StreamArchive : public FD::Kernel::Archive  
		{			
		public:
			StreamArchive(const String &name, const String &archType);
			~StreamArchive();

		public:

			virtual bool isCaseSensitive() const;
			virtual void load();				
			virtual void unload();	
			virtual  FD::Kernel::DataStreamPtr open(const String &filename, bool readOnly = true) const;
			virtual FD::Kernel::DataStreamPtr create(const String &filename) const;
			virtual void remove(const String &filename) const;

			virtual void list(FD::Kernel::StringVector& result, bool recursive = true, bool dirs = false);
			virtual void listFileInfo(FD::Kernel::FileInfoList& result, bool recursive = true, bool dirs = false );
			virtual void find(FD::Kernel::StringVector& result, const String &pattern, bool recursive = true, bool dirs = false );
			virtual void findFileInfo(FD::Kernel::FileInfoList& result, const String &pattern, bool recursive = true, bool dirs = false ) const;

			virtual bool exists(const String &filename);

			virtual INT64 getModifiedTime(const String &filename);

		public:							
			void addItem(const String &filename, const FD::Kernel::DataStreamPtr& item);

		protected:
			mutable FD::Kernel::RecursiveMutex mMutex;
			mutable FD::Kernel::FileInfoList mFileList;
			mutable map<String, FD::Kernel::DataStreamPtr> mStreams;
		};

		class FD_Kernel_Export StreamArchiveFactory  : public  FD::Kernel::ArchiveFactory  
		{
		public:
			StreamArchiveFactory(){}
			virtual ~StreamArchiveFactory(){}

		public:

			String getType() const;

			virtual FD::Kernel::Archive* createInstance(const String& name, bool readOnly);

			void destroyInstance( FD::Kernel::Archive *arch);
		};
	}
}

#endif //_STREAM_ARCHIVE_H_
